const util = require('../../util.js')

const app = getApp()
const log = t => getApp().globalData.logger.log('[entry]' + t)

let secretTouched = 0
let secretTimeout = null
Page({
  data: {
    eyeType: '丹凤眼',
    remake: '一方面是内眼角朝下，眼泪腺被遮蔽，而且上眼皮有盖住下眼皮的倾向 另一方面则是外眼角朝上，这个特征的确很多人不是很明显，但为数也不少，丹凤眼,一方面是内眼角朝下，眼泪腺被遮蔽，而且上眼皮有盖住下眼皮的倾向 另一方面则是外眼角朝上，这个特征的确很多人不是很明显，但为数也不少，丹凤眼一方面是内眼角朝下，眼泪腺被遮蔽，而且上眼皮有盖住下眼皮的倾向 另一方面则是外眼角朝上，这个特征的确很多人不是很明显，但为数也不少，丹凤眼',
    isVip: false,
    goods:[
      {
        image:"https://img.alicdn.com/imgextra/i4/4161056916/O1CN01nJzbPa20xZtzipRgD_!!4161056916.png",
        link:"https://detail.tmall.com/item.htm?spm=a1z10.5-b-s.w4011-23505096767.64.6b265eb7KtIxm1&id=656979931255&rn=dedfbbc67dd8cc1dc68d11b518519914&abbucket=14"
      },
      {
        image:"",
        link:""
      },
      {
        image:"https://img.alicdn.com/imgextra/i4/4161056916/O1CN01nJzbPa20xZtzipRgD_!!4161056916.png",
        link:"https://detail.tmall.com/item.htm?spm=a1z10.5-b-s.w4011-23505096767.64.6b265eb7KtIxm1&id=65131155392532&rn=dedfbbc67dd8cc1dc68d11b518519914&abbucket=14"
      },
      {
        image:"https://img.alicdn.com/imgextra/i4/4161056916/O1CN01nJzbPa20xZtzipRgD_!!4161056916.png",
        link:"https://detail.tmall.com/item.htm?spm=a1z10.5-b-s.w4011-23505096767.64.6b265eb7KtIxm1&id=651311392532"
      },
      {
        image:"",
        link:""
      },
      {
        image:"",
        link:""
      },
      {
        image:"https://img.alicdn.com/imgextra/i4/4161056916/O1CN01nJzbPa20xZtzipRgD_!!4161056916.png",
        link:"https://detail.tmall.com/item.htm?spm=a1z10.5-b-s.w4011-23505096767.64.6b265eb7KtIxm1&id=651311392532"
      }
    ]
  },

  isVip(){
    //调用vip接口
  },

  jumpDetails(e){
    //console.log(e.currentTarget.dataset.goodsId);
    //  my.alert({
    //   content:JSON.stringify(e)
    // })
    let i = e.currentTarget.dataset.goodsId.split("id=")[1].split("&")[0];
   
    //console.log(i,'idddd');

    my.tb.openDetail ({
      itemId: i,
      success: (res) => {
        //my.alert({ content: "success" });
      },
      fail: (res) => {
        //my.alert({ content: "fail - " + res.error });
      }
    });
  },

  //去首页
  goIndex(){
    //my.alert({content:'回到首页'})
    getApp().dataMd(15,`回到首页`);
    
    my.navigateBack({
      url: '/page/entry/entry'
    });

  },

  //加入会员
  joinVip(){
    my.call('navigateToOutside',{
      url:
        'https://market.m.taobao.com/app/sj/member-center-rax/pages/pages_index_index?wh_weex=true&source=ShopSelfUse&sellerId=2210925259336'
      },(res)=>{ 
    })
  },

  currentEyeType: function(){
    my.navigateTo({
      url: '/pages/currentEyetype/currentEyetype'
    })
  },

  openCameraPage: function() {
    log('openCameraPage')
    my.navigateTo({
      url: '/pages/tryOn/tryOn'
    })
  },

  onSecretStart(e) {
    secretTouched += 1
    if (secretTouched === 2 && !secretTimeout) {
      my.vibrateShort()
      secretTimeout = setTimeout(() => {
        secretTouched = 0
        secretTimeout = null
        my.showActionSheet({
          items: ["祕技頁", "Logcat", "上傳小工具"],
          success: result => {
            switch (result.index) {
              case 0:
                log("open secretPage");
                my.navigateTo({
                  url: "/pages/secretPage/secretPage"
                });
                break;
              case 1:
                log("open logPage");
                my.navigateTo({
                  url: "/pages/logPage/logPage"
                });
                break;
              case 2:
                log("open uploadToolPage");
                my.navigateTo({
                  url: "/pages/uploadToolPage/uploadToolPage"
                });
                break;
            }
          }
        })
      }, 3000)
    }
  },

  onSecretEnd(e) {
    secretTouched = 0
    this.removeSecretTimeout()
  },

  removeSecretTimeout() {
    if (secretTimeout) {
      clearTimeout(secretTimeout)
      secretTimeout = null
    }
  },


  showAlertIfEnvNotSupported() {
    const res = this.checkEnv()
    if (!res.supported) {
      my.alert({
        content: res.msg,
        success: () => my.exit && my.exit()
      })
    }
  },

  checkEnv() {
    if (!util.isSupportedAppVersion()) {
      return {
        supported: false,
        msg: '亲，您的淘宝版本也太旧啦，功能无法展现，赶紧去更新一下吧'
      }
    }

    return {
      supported: true,
      msg: ''
    }
  },

  onHide() {
    this.removeSecretTimeout();
  },

  onLoad() {
    
    // for (var i = 0;i < this.data.goods.length;i++) {
    //   var goods = this.data.goods[i]
    //   if(goods.image == null || goods.image == '' || goods.link == null || goods.link == ''){
    //     this.data.goods.splice(i,1);
    //     i--;
    //   }
    // }

    this.setData({
      isVip:getApp().TaobaoMember,
      eyeType:getApp().eyeTestResult.eye_type,
      remake:getApp().eyeTestResult.desc,
      goods:getApp().goodsArrs
    });

  
    this.showAlertIfEnvNotSupported()
    util.readAppParam(options)
    if (app.globalData.logger.getLogLevel() > 0) {
      this.setData({
        cloudEnv: app.globalData.debugSetting.cloudEnv
      })
    }

  },
  onShareAppMessage() {
    // 返回自定义分享信息
    return {
      title: 'wosado睫毛试戴体验',
      desc: '一秒变身',
      path: `pages/index/index?shareMenber=${getApp().userInfoX.nickName}`,
    };
  }
});
